package com.game.tools.exception;

import lombok.Getter;

/**
 * 异常枚举
 */
@Getter
public enum ExceptionEnum {

    /**
     * 未知错误
     */
    UNKNOWN_ERROR(100, "未知异常"),

    /**
     *
     */
    ADD_ERROR(103, "添加失败"),

    /**
     *
     */
    UPDATE_ERROR(104, "更新失败"),

    /**
     * 删除失败
     */
    DELETE_ERROR(105, "删除失败"),

    /**
     * 查询失败
     */
    SELECT_ERROR(106,"查找失败")
    ;

    /**
     * 异常状态码
     */
    private Integer code;

    /**
     * 异常信息
     */
    private String msg;

    ExceptionEnum(Integer code, String msg){
        this.code = code;
        this.msg = msg;
    }

    /**
     * 根据code获取异常对象
     * @param code
     * @return
     */
    public static ExceptionEnum getByCode(Integer code){
        for (ExceptionEnum exceptionEnum : ExceptionEnum.values()){
            if(code == exceptionEnum.getCode()){
                return exceptionEnum;
            }
        }
        return null;
    }
}
